public class Solution{
    public static void main(String[] args) {
        int[] height = {3,1,2,4};
        System.out.println(new Solution().maxArea(height));
    }

    public int maxArea(int[] height) {
        int maxArea = 0;
        int i = 0 ;
        int j = height.length-1;
        while(i<j) {
            int tmp = area(i,j,height[i],height[j]);
            if(height[i]<height[j]){
                i++;
            }else{
                j--;
            }
            if (tmp> maxArea){
                maxArea = tmp;
            }
        }
        return maxArea;
    }

    public int area(int i ,int j,int ai, int aj){
        int sm =0;
        if( ai>aj){
            sm = aj;
        }else{
            sm = ai;
        }
        return (sm)*(j-i);
    }
}